<script src="../../../../Public/bootstrap-switch/bootstrap-switch.min.js"></script>
<link rel="stylesheet" href="../../../../Public/bootstrap-switch/bootstrap-switch.min.css">
<extend name="Public:mainbase" />
<block name="content">
<link rel="stylesheet" href="__PUBLIC__/css/bootstrap-switch.min.css">
<script src="__PUBLIC__/js/bootstrap-switch.min.js" type="text/javascript"></script>


    <div class="panel panel-default">
        <div class="panel-heading">
            <ul class="nav nav-tabs nav-pills">
                <li role="presentation"><a href="javascript:void(0)">详细设置：</a></li>
                <li role="presentation" <eq name="type" value="android">class="active"</eq>><a href="{:U(index)}?type=android">Android</a></li>
                <li role="presentation" <eq name="type" value="ios">class="active"</eq>><a href="{:U(index)}?type=ios">IOS</a></li>               
            </ul>
        </div>
        <div class="panel-body">
        <table width="98%" class="table table-bordered  table-hover table-condensed "  align="center">
        <tr bgcolor="#E7E7E7" >
            <td height="28" colspan="11" background="__PUBLIC__/images/tbg.gif" style="padding-left:10px;">
            ◆ 版本列表 &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-xs btn-warning" data-toggle="modal" data-target=".newversionbox"><i class="glyphicon glyphicon-plus"></i> 添加版本</button>
            </td>
        </tr>
        <tr align="center" bgcolor="#FBFCE2" height="25">
            <td width="6%">ID</td>
            <td width="10%">版本号</td>
            <td width="10%">是否强制更新</td>
            <?php if(strtolower(I('type'))!='ios'){ ?>
            <td width="10%">下载地址</td>
            <?php } ?>
            <td width="10%">操作</td>
        </tr>
        <foreach name="vList" item="val">
        <tr align='center' bgcolor="#FFFFFF" height="26" type="button" role="button" tabindex="{$val.id}"  data-toggle="popover" title="版本说明" data-content="{$val.intro|nl2br=###|htmlspecialchars=###}">
            <td nowrap>{$val.id}</td>
            <td>{$val.version}</td>
            <td><eq name="val.is_force" value="1">强制<else />不强制</eq></td>
            <?php if(strtolower(I('type'))!='ios'){ ?>
            <td><a href="{$val.download_url}" target="_blank">下载</a></td>
            <?php } ?>
            <td>
                <a href="javascript:;" data-id='{$val.id}' class='editversion'>修改</a>
                |
                <a href="javascript:;" data-id='{$val.id}' class='delversion'>删除</a>
            </td>
        </tr>
        </foreach>
        <tr align="right" bgcolor="#F9FCEF">
            <td height="36" colspan="11" align="center">
                <span>{$showpage}</span>
            </td>
        </tr>
        </table>

        </div>

    </div>

<!-- 添加组弹窗 -->
<div class="modal fade newversionbox" tabindex="-1" Auth="dialog" aria-labelledby="add_user_jump" id='newversionbox'>
  <div class="modal-dialog modal-sm" style="width:40%">
        
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">添加{$Think.get.type|default=android|strtoupper=###}版本信息</h4>
        </div>
        <form action="{:U('add')}" method="POST" class="form-horizontal" id="adduserform" style="padding:15px 0" enctype="multipart/form-data">
        <div class="form-group">
            <label for="version" class="col-sm-2 control-label">版本号</label>
            <div class="col-xs-7">
                <input name="version"  type="text" placeholder="请输入版本号" datatype="*2-30" sucmsg=" " errormsg="版本号为2-30个字符" nullmsg="版本号必须填写" class="form-control" value="">
            </div>
            <div class="col-xs-7"></div>
        </div>

        <input type="hidden" name="type" value="{$Think.get.type|default=android|strtolower=###}">
            <?php if(strtolower(I('type'))!='ios'){ ?>
        <div class="form-group">
            <div id="uploader" class="col-xs-10 wu-example">
            <!--用来存放文件信息-->
                <div id="thelist" class="uploader-list"></div>
                <div class="btns">
                    <div id="picker">选择文件</div>
                </div>
            </div>
            <input type="hidden" name="download_url" id="download_url">
        </div>
        <?php } ?>


        <div class="form-group">
            <label for="is_force" class="col-sm-2 control-label">状态</label>
            <div class="col-xs-7">
                <input id="add-status_0" name="is_force" type="radio" value="0" checked="checked">
                <label for="add-status_0">不强制</label>
                <input id="add-status_1" name="is_force" type="radio" value="1">
                <label for="add-status_1">强制</label>&nbsp;&nbsp;

            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">简介</label>
            <div class="col-xs-9"><textarea rows="10" name="intro" class="form-control"></textarea></div>
        </div>

        <div class="add-error-message error item"></div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
              <button type="button" class="btn btn-success" id="addVersion">确定添加</button>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <button type="button" class="btn btn-danger"  data-dismiss="modal">取消</button>
            </div>
          </div>
        </form>
    </div>
  </div>
</div>

<!-- 修改组弹窗 -->
<div class="modal fade editversionbox" tabindex="-1" Auth="dialog" aria-labelledby="add_user_jump" id='editversionbox'>
  <div class="modal-dialog modal-sm" style="width:40%">
        
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">修改{$Think.get.type|default=android|strtoupper=###}版本信息</h4>
        </div>
        <form action="{:U('edit')}" method="POST" class="form-horizontal" style="padding:15px 0" enctype="multipart/form-data">
        <input name='id' type="hidden" value=''>
        <div class="form-group">
            <label for="version" class="col-sm-2 control-label">版本号</label>
            <div class="col-xs-7">
                <input name="version" type="text" placeholder="请输入版本号" datatype="*2-30" sucmsg=" " errormsg="版本号为2-30个字符" nullmsg="版本号必须填写" class="form-control" value="">
            </div>
            <div class="col-xs-7"></div>
        </div>
            <input type="hidden" name="type" value="{$Think.get.type|default=android|strtolower=###}">
            <?php if(strtolower(I('type'))!='ios'){ ?>
           <div class="form-group">
                <div id="uploader" class="col-xs-10 wu-example">
                <!--用来存放文件信息-->
                    <div id="thelist" class="uploader-list"></div>
                    <div class="btns">
                        <div id="picker">选择文件</div>
                    </div>
                </div>
                <input type="hidden" name="download_url" id="download_url">
            </div>
            <?php } ?>


            <div class="form-group">
                <label for="is_force" class="col-sm-2 control-label">状态</label>
                <div class="col-xs-7">
                    <input id="edit-status_0" name="is_force" type="radio" value="0" checked="checked">
                    <label for="edit-status_0">不强制</label>
                    <input id="edit-status_1" name="is_force" type="radio" value="1">
                    <label for="edit-status_1">强制</label>&nbsp;&nbsp;

                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">简介</label>
                <div class="col-xs-9"><textarea rows="10" name="intro" class="form-control"></textarea></div>
            </div>

        <div class="add-error-message error item"></div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
              <button type="button" class="btn btn-success" id="editVersion">确定修改</button>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <button type="button" class="btn btn-danger"  data-dismiss="modal">取消</button>
            </div>
          </div>
        </form>
    </div>
  </div>
</div>

<!--image upload-->
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/webUploader/webuploader.css">
    <script type="text/javascript" src="__PUBLIC__/webUploader/webuploader.min.js"></script>



<script type="text/javascript">
    var mx,my;
$('.editversion').click(function(){
    $('#editversionbox form').get(0).reset();
    $.get("{:U('ajaxGetVersionInfo')}?id="+$(this).data('id'),function(data){
        if(data!=0){
            $("#editversionbox [name=id]").val(data.id);
            $("#editversionbox [name=version]").val(data.version);
            $("#editversionbox [name=intro]").val(data.intro);
            $("#editversionbox [name=type]").val(data.type);
            $("#edit-status_" + data.is_force).get(0).click();
        }
    })
    $('#editversionbox .Validform_checktip').empty().attr('class','Validform_checktip');
    $('.Validform_error').removeClass('Validform_error');
    $('#editversionbox').modal('show');
})

$('.delversion').click(function(){
    if(confirm('是否确定删除此版本？')){
        var obj=this;
        $.get('{:U("ajaxdelversion")}?id='+$(obj).data('id'),function(data){
            if(data==1){
                $(obj).parents('tr').remove();
            }
        })
    }
})



$('[data-toggle="popover"]').popover({
    "trigger":"hover",
    'html':true,
    "placement":"right",

});
    $('[data-toggle="popover"]').on('show.bs.popover', function () {
        $(this).mousemove(function(e) { //传递事件对象e
            var mx = e.pageX;
            var my = e.pageY;
            $(this).next('.popover').css({
                'position':'fixed',
                'left':mx+"px",
                'top':my+'px'
            })

        });
    })

    $('[data-toggle="popover"]').on('hidden.bs.popover', function () {
        $(this).removeAttr('style');
    })

var uploader;
$("#addVersion").click(function(){

            var version=$("#newversionbox [name=version]").val();
            var type=$("#newversionbox [name=type]").val().toLowerCase();

            if(version!="" && type=='android'){
                uploader.upload();
            }else if(version==""){
                alert("请填写版本号");
            }else{
                $("#newversionbox form").submit();
            }

})
$("#editVersion").click(function(){
    if(uploader.getFiles().length==0){
        $("#editversionbox form").submit();
    }else{
        uploader.upload();
    }    
})


    $('#newversionbox,#editversionbox').on('shown.bs.modal', function (e) {
        var _this=this;
            uploader = WebUploader.create({
                auto: false,
                swf: 'http://cdn.bootcss.com/webuploader/0.1.1/Uploader.swf',
                server: 'http://upload.qiniu.com/',
                pick: $(_this).find("#picker"),
                fileNumLimit:1,
                formData:{
                    token:"{$uploadToken}"
                },
                accept: {
                    title: 'Applications',
                    extensions: 'apk',
                    mimeTypes: 'application/vnd.android'
                }
            });

            uploader.on('beforeFileQueued',function(){
                $(_this).find("#fileList").empty();
                uploader.reset();
                $(_this).find("#download_url").val("");
            })

            uploader.on( 'fileQueued', function( file ) {
                $(_this).find("#thelist").append( '<div id="' + file.id + '" class="item">' +
                    '<h4 class="info">' + file.name + '</h4>' +
                    '<p class="state">等待上传...</p>' +
                '</div>' );
            })

           uploader.on( 'uploadProgress', function( file, percentage ) {
                var $li = $(_this).find( '#'+file.id ),
                    $percent = $li.find('.progress .progress-bar');

                // 避免重复创建
                if ( !$percent.length ) {
                    $percent = $('<div class="progress progress-striped active">' +
                      '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                      '</div>' +
                    '</div>').appendTo( $li ).find('.progress-bar');
                }

                $li.find('p.state').text('上传中');

                $percent.css( 'width', percentage * 100 + '%' );
            });


            uploader.on( 'uploadSuccess', function( file ,response ) {
                $(_this).find( '#'+file.id ).addClass('upload-state-done');
                $(_this).find("#download_url").val("http://download.jianweitv.com/"+response.key);
               $(_this).find("form").submit();
            });

            uploader.on( 'uploadError', function( file ) {
                var $li = $(_this).find( '#'+file.id ),
                        $error = $li.find('div.error');

                if ( !$error.length ) {
                    $error = $(_this).find('<div class="error"></div>').appendTo( $li );
                }

                $error.text('上传失败');
            });

            uploader.on( 'uploadComplete', function( file ) {
                $(_this).find( '#'+file.id ).find('.progress').remove();
            });
        })



        $('#newversionbox,#editversionbox').on('hidden.bs.modal', function (e) {
            var _this=this;
            uploader.reset();
            uploader.destroy();
            $(_this).find("#fileList").empty();
            $(_this).find('form').get(0).reset();
        })

</script>
</block>